package com.example.sunmiv1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.IndexDetailsBean;
import com.example.sunmiv1.utils.net.ACache;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IndexDetailsAdapter extends BaseAdapter {

    private Context context;
    private List<IndexDetailsBean.ListBean> list;
    ViewHolder viewHolder;
    private ACache aCache;

    public IndexDetailsAdapter(Context context, List<IndexDetailsBean.ListBean> list) {
        this.context = context;
        this.list = list;
        aCache = ACache.get(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.index_details_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        IndexDetailsBean.ListBean bean = list.get(position);
        viewHolder.indexDetailsAdapterName.setText(bean.getName());
        viewHolder.indexDetailsAdapterTurnover.setText(bean.getSellinfo().getAllmoney() + "");
        viewHolder.indexDetailsAdapterCollectingNum.setText(bean.getSellinfo().getCount() + "");
        viewHolder.indexDetailsAdapterWxPay.setText(bean.getSellinfo().getWx() + "");
        if ("0".equals(aCache.getAsString("credit"))) {
            viewHolder.indexDetailsAdapterCreditLin.setVisibility(View.INVISIBLE);
            viewHolder.indexDetailsAdapterRepayLin.setVisibility(View.GONE);
        } else {
            viewHolder.indexDetailsAdapterCreditLin.setVisibility(View.VISIBLE);
            viewHolder.indexDetailsAdapterRepayLin.setVisibility(View.VISIBLE);
        }
        if (bean.getId() == 0) {
            viewHolder.llIndexDetailsAdapterCashier.setVisibility(View.GONE);
            viewHolder.llIndexDetailsAdapterShop.setVisibility(View.VISIBLE);
            viewHolder.indexDetailsAdapterView.setVisibility(View.GONE);
            viewHolder.indexDetailsAdapterName.setVisibility(View.GONE);
            viewHolder.indexDetailsAdapterShopWx.setText(bean.getSellinfo().getXcx() + "");
            viewHolder.indexDetailsAdapterShopVip.setText(bean.getSellinfo().getVipcard() + "");
            viewHolder.indexDetailsAdapterShopRefund.setText(bean.getSellinfo().getRefund() + "");
            viewHolder.indexDetailsAdapterShopRecharge.setText(bean.getSellinfo().getVipaddmoney() + "");
        } else {
            viewHolder.llIndexDetailsAdapterCashier.setVisibility(View.VISIBLE);
            viewHolder.llIndexDetailsAdapterShop.setVisibility(View.GONE);
            viewHolder.indexDetailsAdapterView.setVisibility(View.VISIBLE);
            viewHolder.indexDetailsAdapterName.setVisibility(View.VISIBLE);
            viewHolder.indexDetailsAdapterAliPay.setText(bean.getSellinfo().getZfb() + "");
            viewHolder.indexDetailsAdapterMoneyPay.setText(bean.getSellinfo().getXj() + "");
            viewHolder.indexDetailsAdapterVipPay.setText(bean.getSellinfo().getVipcard() + "");
            viewHolder.indexDetailsAdapterOther.setText(bean.getSellinfo().getOther_pay() + "");
            viewHolder.indexDetailsAdapterRefund.setText(bean.getSellinfo().getRefund() + "");
            viewHolder.indexDetailsAdapterVipRecharge.setText(bean.getSellinfo().getVipaddmoney() + "");
            viewHolder.indexDetailsAdapterCredit.setText(bean.getSellinfo().getArrearageMoney() + "");
            viewHolder.indexDetailsAdapterRepay.setText(bean.getSellinfo().getRepaymentMoney() + "");
//            viewHolder.indexDetailsAdapterDJJ.setText(bean.getPay_coupon_fee() + "");
        }
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.indexDetails_adapter_name)
        TextView indexDetailsAdapterName;
        @BindView(R.id.indexDetails_adapter_view)
        View indexDetailsAdapterView;
        @BindView(R.id.indexDetails_adapter_turnover)
        TextView indexDetailsAdapterTurnover;
        @BindView(R.id.indexDetails_adapter_collectingNum)
        TextView indexDetailsAdapterCollectingNum;
        @BindView(R.id.indexDetails_adapter_wxPay)
        TextView indexDetailsAdapterWxPay;
        @BindView(R.id.indexDetails_adapter_aliPay)
        TextView indexDetailsAdapterAliPay;
        @BindView(R.id.indexDetails_adapter_moneyPay)
        TextView indexDetailsAdapterMoneyPay;
        @BindView(R.id.indexDetails_adapter_vipPay)
        TextView indexDetailsAdapterVipPay;
        @BindView(R.id.indexDetails_adapter_other)
        TextView indexDetailsAdapterOther;
        @BindView(R.id.indexDetails_adapter_refund)
        TextView indexDetailsAdapterRefund;
        @BindView(R.id.indexDetails_adapter_vip_recharge)
        TextView indexDetailsAdapterVipRecharge;
        @BindView(R.id.indexDetails_adapter_credit)
        TextView indexDetailsAdapterCredit;
        @BindView(R.id.indexDetails_adapter_creditLin)
        LinearLayout indexDetailsAdapterCreditLin;
        @BindView(R.id.indexDetails_adapter_repay)
        TextView indexDetailsAdapterRepay;
//        @BindView(R.id.indexDetails_adapter_djj)
//        TextView indexDetailsAdapterDJJ;
        @BindView(R.id.indexDetails_adapter_repayLin)
        LinearLayout indexDetailsAdapterRepayLin;
        @BindView(R.id.ll_indexDetails_adapter_cashier)
        LinearLayout llIndexDetailsAdapterCashier;
        @BindView(R.id.indexDetails_adapter_shop_wx)
        TextView indexDetailsAdapterShopWx;
        @BindView(R.id.indexDetails_adapter_shop_vip)
        TextView indexDetailsAdapterShopVip;
        @BindView(R.id.indexDetails_adapter_shop_refund)
        TextView indexDetailsAdapterShopRefund;
        @BindView(R.id.indexDetails_adapter_shop_recharge)
        TextView indexDetailsAdapterShopRecharge;
        @BindView(R.id.ll_indexDetails_adapter_shop)
        LinearLayout llIndexDetailsAdapterShop;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
